export default {
    data() {
        return {
            list:[]
        }
    },
    //进入页面加载
    mounted: function() {
        var that = this;
        //在缓存中获取值
        that.user_name = sessionStorage.getItem("user_name");
        that.user_id = sessionStorage.getItem("user_id");
        that.token = sessionStorage.getItem("access-token");
        if((!that.token) || (!that.user_id) || (!that.user_name)) {
            that.$router.push('/login');
        }
        //请求员工列表
        that.getMemberList();
    },

    methods: {
		add:function(){
			var that=this;
			that.$router.push({path: '/user/member_grade'});
		},

        /**
         * 获取列表
         */
        getMemberList:function () {
            var that = this;
            //初始化数据
            that.list = [];
            //请求登陆接口
            that.$http.post(that.adminApi.api_url + "/api/member/index", {
                token: that.token,
            }, {
                emulateJSON: true
            }).then(
                function(res) {
                    // 处理成功的结果
                    if(res.body) {
                        for(var i in res.body) {
                            that.list.push({
                                i: i,
                                id: res.body[i].id,
                                number: res.body[i].sort,
                                header: "<img src =" + res.body[i].icon + ">",
                                grade:res.body[i].name,
                                amoney:res.body[i].price,
                                explain:res.body[i].describe,
                                illustrate: "<span>" + res.body[i].system_manager_id + "<span><br /><span>" + res.body[i].system_manager_time + "<span>"
                            });
                        }
                    }
                },
                function() {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },


        /**
         * 修改
         * @param id
         */
        edit:function (id) {
            let that = this;
            that.$router.push({path:'/user/member_grade',query:{member_id:id}});
        },

        /**
         * 删除
         * @param e
         */
        deleteGrade:function (e) {
            let that = this;
            that.$confirm('此操作将永久删除该等级, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                that.doDelete(e);
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        //执行删除
        doDelete:function (e) {
            var that = this;
            //请求登陆接口
            that.$http.post(that.adminApi.api_url + "/api/member/del", {
                token: that.token,
                id: e
            }, {
                emulateJSON: true
            }).then(
                function(res) {
                    // 处理成功的结果
                    that.$message({
                        type: 'success',
                        message: `操作提示: ${ '删除成功' }`
                    });
                    that.getMemberList();
                },
                function() {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },
    }
}